package com.css.fxfzypg.modules.saresults.controller;

import com.css.fxfzypg.base.response.RestResponse;
import com.css.fxfzypg.modules.saresults.entity.DzqhApAsicMapEntity;
import com.css.fxfzypg.modules.saresults.param.AdminUpdateParam;
import com.css.fxfzypg.modules.saresults.param.ApTemporarySaveParam;
import com.css.fxfzypg.modules.saresults.param.ApproveParam;
import com.css.fxfzypg.modules.saresults.service.SaResultsService;
import com.css.fxfzypg.modules.saresults.vo.HistoryVo;
import com.css.fxfzypg.modules.saresults.vo.SaResultsHlVo;
import com.css.fxfzypg.modules.saresults.vo.SaResultsVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 安评成果
 */
@RestController
@RequestMapping("saResults")
@Slf4j
public class SaResultsController {

    @Autowired
    private SaResultsService saResultsService;


    /**
     * 安评成果目录查询(修改回显)
     *
     * @param projectId
     * @return
     */
    @GetMapping("getSaResultsById")
    public RestResponse getSaResultsById(String projectId) {
        return saResultsService.getSaResultsById(projectId);
    }

    /**
     * 安评成果目录提交，保存，修改
     *
     * @param saResultsVo
     * @return
     */
    @PostMapping("saveOrUpdateSaResults")
    public RestResponse saveOrUpdateSaResults(@RequestBody SaResultsVo saResultsVo) {
        return saResultsService.saveOrUpdateSaResults(saResultsVo);
    }
    /**
     * 安评成果目录项目信息分页查询
     * @param
     * @return
     */
    @GetMapping("getSaResultsProject")
    public RestResponse getSaResultsProject(DzqhApAsicMapEntity mapEntity, HttpServletRequest request,String geom) {
        return saResultsService.getSaResultsProject(mapEntity, request,geom);
    }

    /**
     * 安评成果目录项目信息删除
     *
     * @param
     * @return
     */
    @GetMapping("deleteSaResultsProject")
    public RestResponse deleteSaResultsProject(String projectId,String deleteReason,String reviewComments,String approvalStatus) {
        return saResultsService.deleteSaResultsProject(projectId,deleteReason,reviewComments,approvalStatus);
    }

    /**
     * 安评成果数据导入
     *
     * @return
     */
    @PostMapping("importExcelSaResults")
    public RestResponse importExcelSaResults(MultipartFile file) {
        return saResultsService.importExcelSaResults(file);
    }

    /**
     * 安评成果数据导出
     *
     * @return
     */
    @GetMapping("exportExcelSaResults")
    public void exportExcelSaResults(HttpServletResponse response, String projectId) {
        saResultsService.exportExcelSaResults(response, projectId);
    }

    /**
     * 安评成果目录孔位信息分页查询
     *
     * @return
     */
    @GetMapping("getSaResultsHl")
    public RestResponse getSaResultsHl(SaResultsHlVo saResultsHlVo, HttpServletRequest request,String geom) {
        return saResultsService.getSaResultsHl(saResultsHlVo, request,geom);
    }

    /**
     * 根据用户id查询未提交数据
     * @return
     */
    @GetMapping("notSubmitted")
    public RestResponse notSubmitted() {
        return saResultsService.notSubmitted();
    }

    /**
     * 历史记录查询
     */
    @GetMapping("queryHistory")
    public RestResponse queryHistory(String originalDataId) {
        return saResultsService.queryHistory(originalDataId);
    }

    /**
     * 查询所有项目
     * @param
     * @return
     */
    @GetMapping("queryAllProject")
    public RestResponse queryAllProject() {
        return saResultsService.queryAllProject();
    }


    /**
     * 查询用户是否是管理员
     * @param
     * @return
     */
    @GetMapping("queryUserRole")
    public RestResponse queryUserRole() {
        return saResultsService.queryUserRole();
    }

    @GetMapping("test1111")
    public RestResponse test1111(){
        return saResultsService.test1111();
    }

    /**
     * 新增或修改
     * @param param
     * @return
     */
    @PostMapping("saveOrUpdate")
    public RestResponse saveOrUpdate(@RequestBody ApTemporarySaveParam param){
        try {
            saResultsService.saveOrUpdate(param);
            return RestResponse.succeed("成功!");
        } catch (Exception e) {
            log.error("post saveOrUpdate error:{}",e.getMessage(),e);
            return RestResponse.fail("失败!");
        }
    }

    /**
     * 审批
     * @param param
     * @return
     */
    @PostMapping("approve")
    public RestResponse approve(@RequestBody ApproveParam param){
        try {
            saResultsService.approve(param);
            return RestResponse.succeed("审批成功!");
        } catch (Exception e) {
            log.error("post approve error:{}",e.getMessage(),e);
            return RestResponse.fail("审批失败!");
        }
    }

    /**
     * 管理员修改用户数据
     * @param param
     * @return
     */
    @PostMapping("adminUpdate")
    public RestResponse adminUpdate(@RequestBody AdminUpdateParam param){
        try {
            saResultsService.adminUpdate(param);
            return RestResponse.succeed("成功!");
        } catch (Exception e) {
            log.error("post adminUpdate error:{}",e.getMessage(),e);
            return RestResponse.fail("失败!");
        }
    }

    /**
     * 删除数据
     * @param param
     * @return
     */
    @PostMapping("deleteById")
    public RestResponse deleteById(@RequestBody AdminUpdateParam param){
        try {
            saResultsService.deleteById(param);
            return RestResponse.succeed("成功!");
        } catch (Exception e) {
            log.error("post deleteById error:{}",e.getMessage(),e);
            return RestResponse.fail("失败!");
        }
    }

    /**
     * 查询操作记录
     */
    @GetMapping("getHistory")
    public RestResponse getHistory(String id,Integer type){
        List<HistoryVo> list = saResultsService.getHistory(id,type);
        return RestResponse.succeed(list);
    }
}
